﻿using System.Collections.Generic;

namespace Sidvall.WorkItemManager.UI.Entities
{
    public partial class WebContext
    {
        #region Public Members

        #region LoadWebResult

        public void LoadWebResult(IEnumerable<WebResult> items)
        {
            this.WebTargets?.LoadWebResult(items);
        }

        #endregion

        #region Deserialize

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        public static WebContext Deserialize(string value)
        {
            WebContext item;
            Sidvall.WorkItemManager.Net.Services.V1.WebContext data;

            data = null;
            try
            {
                if (!string.IsNullOrWhiteSpace(value))
                    data = Sidvall.Serialization.SerializerManager.Current.Deserialize<Sidvall.WorkItemManager.Net.Services.V1.WebContext>(value);
            }
            catch
            {
                data = null;
            }
            if (data == null)
            {
                data = new Sidvall.WorkItemManager.Net.Services.V1.WebContext()
                {
                };
            }
            item = new WebContext();
            item.Import(data, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.None, Sidvall.Data.DataRowState.Unchanged));

            return item;
        }

        #endregion
        #region Serialize

        public static string Serialize(WebContext item)
        {
            Sidvall.WorkItemManager.Net.Services.V1.WebContext data;

            data = new Net.Services.V1.WebContext();
            data.Import(item, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.None, null));

            return Sidvall.Serialization.SerializerManager.Current.SerializeObject(data);
        }

        #endregion

        #endregion
    }
}